$(function () {
  $('.search-icon').on('click', function() {
    $('.search-form').css({
      width: '240px',
    });
  })
  $(document).on('click', function(e) {
    if (!$(e.target).closest('.search-index').length) {
      $('.search-form').css({
        width: '0px',
      });
    }
  });
  $(window).on('scroll', fixedHeader);
  fixedHeader();
  function fixedHeader() {
    if ($(window).scrollTop() > 50) {
      $('#header').addClass('header-scrolled');
      $('#right-fixed .scroll-top').css({
        visibility: 'visible',
      });
    } else {
      $('#header').removeClass('header-scrolled');
      $('#right-fixed .scroll-top').css({
        visibility: 'hidden',
      });
    }
  }
  $('.navbar-toggle').on('click', function() {
    $(document.body).toggleClass('navbar-on');
  })
  $('.navbar-on-shadow').on('click', function() {
    $(document.body).removeClass('navbar-on');
  });
  $('.header .m-dropdown').on('click', function() {
    $(this).parent().toggleClass('active');
    $(this).parent().find('.dropdown-menu').slideToggle();
  })
  $('#right-fixed a.weixin').on('mouseenter', function() {
    console.log('mouseenter', $(this).parent()[0], $(this).parent().find('.pop')[0]);
    $(this).parent().find('.pop').css({
      visibility: 'visible',
    });
  }).on('mouseleave', function() {
    $(this).parent().find('.pop').css({
      visibility: 'hidden',
    })
  })
  $("img.lazy").lazyload();
  const observer = new IntersectionObserver((entries, observer) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        // 元素进入视口，添加动画类
        console.log(entry.target, $(entry.target).data('animate'))
        entry.target.classList.add($(entry.target).data('animate'));
        observer.unobserve(entry.target);
      }
    });
  }, {
    rootMargin: '10px',
    threshold: 0.01
  });
  $('.animate__animated').each((index, element) => {
    observer.observe(element);
  });
})